
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_ManufacturerTemplateDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            ManufacturerTemplate manufacturerTemplate = ManufacturerTemplateManager.GetByManufacturerTemplateID(this.ManufacturerTemplateID);
            if (manufacturerTemplate != null)
            {
                this.txtName.Text = manufacturerTemplate.Name;
                this.txtTemplatePath.Text = manufacturerTemplate.TemplatePath;
                this.txtDisplayOrder.Value = manufacturerTemplate.DisplayOrder;
                this.lblCreatedOn.Text = manufacturerTemplate.CreatedOn.ToString();
                this.lblUpdatedOn.Text = manufacturerTemplate.UpdatedOn.ToString();
            }
            else
                Response.Redirect("ManufacturerTemplates.aspx");
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    ManufacturerTemplate manufacturerTemplate = ManufacturerTemplateManager.GetByManufacturerTemplateID(this.ManufacturerTemplateID);
                    if (manufacturerTemplate != null)
                    {
                        manufacturerTemplate = ManufacturerTemplateManager.UpdateManufacturerTemplate(manufacturerTemplate.ManufacturerTemplateID, txtName.Text,
                            txtTemplatePath.Text, txtDisplayOrder.Value, manufacturerTemplate.CreatedOn, DateTime.Now);
                    }

                    Response.Redirect("ManufacturerTemplates.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                ManufacturerTemplateManager.DeleteManufacturerTemplate(this.ManufacturerTemplateID);
                Response.Redirect("ManufacturerTemplates.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int ManufacturerTemplateID
        {
            get
            {
                return CommonHelper.QueryStringInt("ManufacturerTemplateID");
            }
        }
    }
}
